/*
 * rdi_perftest.c
 *
 *  Created on: Nov 30, 2012
 *      Author: Andrey Belomutskiy
 */

#include "main.h"
#include "rfi_perftest.h"

#include "rfirtc.h"
#include "rficonsole.h"

void testSystemCalls(int count) {
	time_t start, time;
	long result;
	start = currentTimeMillis();
	for (int i = 0; i < count; i++)
		result += chTimeNow();
	time = currentTimeMillis() - start;
	if (result != 0)
		print("Finished %d iterations of 'chTimeNow()' in %dms\r\n", count,
				time);

	count /= 10;

	start = currentTimeMillis();
	for (int i = 0; i < count; i++)
		result += currentTimeMillis();
	time = currentTimeMillis() - start;
	if (result != 0)
		print("Finished %d iterations of 'currentTimeMillis' in %dms\r\n",
				count, time);

}

void testMath(int count) {
	time_t start, time;
	start = currentTimeMillis();
	long templ = 1;
	for (int i = 0; i < count; i++)
		templ += templ;
	time = currentTimeMillis() - start;
	if (templ != 0)
		print("Finished %d iterations of long summation in %dms\r\n", count,
				time);

	start = currentTimeMillis();
	int tempi = 1;
	for (int i = 0; i < count; i++)
		tempi += (tempi + 100) / 130;
	time = currentTimeMillis() - start;
	if (tempi != 0)
		print("Finished %d iterations of int division in %dms\r\n", count,
				time);

	start = currentTimeMillis();
	templ = 1;
	for (int i = 0; i < count; i++)
		templ += (templ + 100) / 130;
	time = currentTimeMillis() - start;
	if (templ != 0)
		print("Finished %d iterations of long division in %dms\r\n", count,
				time);

	start = currentTimeMillis();
	float tempf = 1;
	for (int i = 0; i < count; i++)
		tempf += tempf;
	time = currentTimeMillis() - start;
	if (tempf != 0)
		print("Finished %d iterations of float summation in %dms\r\n", count,
				time);

	start = currentTimeMillis();
	tempf = 1;
	for (int i = 0; i < count; i++)
		tempf += (tempf + 100) / 130.0;
	time = currentTimeMillis() - start;
	if (tempf != 0)
		print("Finished %d iterations of float division in %dms\r\n", count,
				time);

	start = currentTimeMillis();
	double tempd = 1;
	for (int i = 0; i < count; i++)
		tempd += tempd / 2;
	time = currentTimeMillis() - start;
	if (tempd != 0)
		print("Finished %d iterations of double summation in %dms\r\n", count,
				time);

	start = currentTimeMillis();
	tempd = 1;
	for (int i = 0; i < count; i++)
		tempd += (tempd + 100) / 130.0;
	time = currentTimeMillis() - start;
	if (tempd != 0)
		print("Finished %d iterations of double division in %dms\r\n", count,
				time);
}
